package com.library.service;

import com.library.dao.AdminRepository;
import com.library.dao.UserRepository;
import com.library.entity.Admin;
import com.library.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginService {

    @Autowired
    private UserRepository userRepository;
    @Autowired
    private AdminRepository adminRepository;


    public User userLogin(String userName,String password){
        User user=userRepository.findByName(userName);
        if(user==null||!password.equals(user.getPassword())){
            return null;
        }
        return user;
    }

    public Admin adminLogin(String userName,String password){
        Admin admin= adminRepository.findByName(userName);
        if(admin==null||!password.equals(admin.getPassword())){
            return null;
        }
        return admin;
    }

    public Admin findAdminByName(String userName){
        return adminRepository.findByName(userName);
    }

    public User findUserByName(String userName){
        return userRepository.findByName(userName);
    }
}
